package net.caixiaomi.info.adapter;

import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import net.caixiaomi.info.R;
import net.caixiaomi.info.app.CommonApp;
import net.caixiaomi.info.base.quickadapter.BaseQuickAdapter;
import net.caixiaomi.info.base.quickadapter.BaseViewHolder;
import net.caixiaomi.info.model.MineItem;

import java.util.List;

/**
 * 我的页面
 */

public class MineAdapter extends BaseQuickAdapter<MineItem, BaseViewHolder> {

    public MineAdapter(@LayoutRes int layoutResId, @Nullable List<MineItem> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, MineItem item) {
        try {
            int position = helper.getAdapterPosition() - getHeaderLayoutCount();
            helper.itemView.setId(Integer.valueOf(item.getId()));
            if (item.getIconId() > 0) {
                Glide.with(CommonApp.getInstance()).load(item.getIconId()).into((ImageView) helper.getView(R.id.image));
            } else {
                Glide.with(CommonApp.getInstance()).load(item.getIcon()).into((ImageView) helper.getView(R.id.image));
            }
            helper.setText(R.id.name, item.getTitle());
            helper.setText(R.id.text, item.getDetail());
            helper.setGone(R.id.more, TextUtils.isEmpty(item.getDetail()));
            helper.setGone(R.id.text, !TextUtils.isEmpty(item.getDetail()));

            RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) helper.itemView.getLayoutParams();
            if (position == 0) {
                layoutParams.topMargin = (int) CommonApp.getInstance().getResources().getDimension(net.caixiaomi.info.R.dimen.padding_8);
            } else {
                layoutParams.topMargin = item.getMargin();

            }
            helper.setGone(R.id.point, item.getVisablePoint() != 0);
            helper.setVisible(R.id.line, item.getVisableLine() == 1);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
